import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ImageManager imageManager = new ImageManager();
        Scanner scanner = new Scanner(System.in);
        boolean running = true;

        while (running) {
            // 显示菜单
            System.out.println("\n=== 图片下载系统 ===");
            System.out.println("1. 下载图片");
            System.out.println("2. 查看所有图片");
            System.out.println("3. 搜索图片");
            System.out.println("4. 退出");
            System.out.print("请选择操作 (1-4): ");

            // 读取用户输入
            int choice;
            try {
                choice = Integer.parseInt(scanner.nextLine());
            } catch (NumberFormatException e) {
                System.out.println("输入错误，请重新输入！");
                continue;
            }

            // 处理用户选择
            switch (choice) {
                case 1:
                    System.out.print("请输入图片网址(URL): ");
                    String url = scanner.nextLine();
                    imageManager.downloadImage(url);
                    break;
                case 2:
                    imageManager.listImages();
                    break;
                case 3:
                    System.out.print("请输入要搜索的图片名称: ");
                    String name = scanner.nextLine();
                    imageManager.searchImage(name);
                    break;
                case 4:
                    running = false;
                    System.out.println("即将退出程序");
                    break;
                default:
                    System.out.println("输入错误，请重新输入！");
            }
        }

    }
}
